import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class Main {
    public static void main(String[] args) {
        //加载
        try{
            Class.forName("com.mysql.cj.jdbc.Driver");
            System.out.println("加载驱动成功！");
        } catch (Exception e){
            System.out.println("加载驱动失败！");
        }


        //连接数据库
         String url ="jdbc:mysql://localhost:3306/demo0913";
         String userName ="root";
         String password ="Ddj0302.";


        try{
            Connection connection = DriverManager.getConnection(url,userName,password);
            if (connection !=null) {
                System.out.println("连接成功！");
            }else {
                System.out.println("连接失败！");
            }
            //查询操作
            Statement statement =connection.createStatement();

            String sql = "select * from use1";
            ResultSet resultSet=statement.executeQuery(sql);
            while(resultSet.next()){
                System.out.println(resultSet.getString("姓名")+","+resultSet.getString("学号"));
            }


        }catch (Exception e){
            System.out.println("获取数据库信息失败！");
        }
    }
}


